#include "QBFlags.h"
#include <qbprotocol/include/SSQBModel.h>

const std::string CQBFlags::CommonPageAddedFlag_Key = std::string("CommonPageAddedKey");
const std::string CQBFlags::CommonPageAddedFlag_Val = std::string("Added");

void CQBFlags::Update(xQBFlagsAck_c *pdata)
{
	if (!pdata)
		return;

	for (auto itr = pdata->listFlags.begin(); itr != pdata->listFlags.end(); ++itr)
	{
		const xQbFlag_c &flag = *itr;
		m_data.insert(make_pair(std::string(flag.szKey), std::string(flag.szValue)));
	}

	m_bFlagInitialized = true;
}

void CQBFlags::Update(xQbFlagAdd_c *pdata)
{
	if (strlen(pdata->flag_.szKey)>0)
		m_data.insert(make_pair(std::string(pdata->flag_.szKey), std::string(pdata->flag_.szValue)));
}

void CQBFlags::Clear()
{
	m_data.clear();
}

bool CQBFlags::GetValue(const char *pkey, std::string& value)
{
	if (pkey == NULL)
		return false;

	std::map<std::string, std::string>::iterator itrFind = m_data.find(std::string(pkey));
	if (itrFind!=m_data.end())
	{
		value = itrFind->second;
		return true;
	}

	return false;
}